import {getFormSchema} from '../definitions/constants'
/**
 * 生成基础属性Form表单（部分hardCode）
 */
export const buildAttributeForm = function (options) {
  let rules = []
  let formItemRule = {}
  options.forEach((option) => {
    // 判断当前schemaType不等于custom，并且value的类型不是对象，生成简单输入项规则
    if (
      option.schemaType !== 'custom' &&
        Object.prototype.toString.call(option.value) !== '[object Object]'
    ) {
      /**
       * option.schemaType的特殊处理
       * option.schemaType === 'elColorPicker'颜色选择器,需要设置props:{showAlpha:true}
       */
      formItemRule = {
        type: option.schemaType,
        field: option.name,
        title: option.formLabelName,
        value: option.value,
        props: option.schemaType === 'elColorPicker' ? {showAlpha: true, size: 'small', popperClass: 'color-dropdown'} : {type: option.schemaType},
        // Antdesign 栅格布局
        wrap: {
          labelCol: {span: 4},
          wrapperCol: {span: 20}
        }
      }
    } else {
      formItemRule = getFormSchema(option.schemaType, option)
      console.log(formItemRule)
    }
    rules.push(formItemRule)
  })
  return rules
}
